﻿// 
// Salient.Web 
// (c) 2009 Sky Sanders (sky.sanders@gmail.com)
// Licensed under the Microsoft Public License (Ms-PL)
// 
using System;
using System.Web.Script.Serialization;
using System.Web.Services;
using System.Web.UI;
using System.Web.UI.HtmlControls;

namespace Salient.Web
{
    public class WebForm1 : Page
    {
        protected HtmlForm form1;

        protected void Page_Load(object sender, EventArgs e)
        {
            if (Request["delay"] != null)
            {
                DateTime endTime = DateTime.Now.AddMilliseconds(Convert.ToInt32(Request["delay"]));

                while (DateTime.Now < endTime)
                {
                    // noop
                }
            }

            string name = null;

            if (Request.QueryString["name"] != null || Request["name"] != null)
            {
                name = Request.QueryString["name"] ?? Request["name"];
            }

            if (name != null)
            {
                TestObj obj = new TestObj(name);

                Response.Clear();
                Response.ContentType = "text/json";
                Response.Write((new JavaScriptSerializer()).Serialize(obj));
                Response.End();
            }
        }

        [WebMethod]
        public static string Echo(string input)
        {
            return input;
        }

        [WebMethod]
        public static TestObj EchoTestObject(TestObj input)
        {
            return input;
        }
    }
}